package com.accountsmanager.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.accountsmanager.dto.DataDictionary;
import com.accountsmanager.dto.NoteBaseInfo;
import com.accountsmanager.dto.UserInfo;
import com.common.dao.BaseDao;

public class LoginDao extends BaseDao{
	
	public boolean userLogin(String userCount){
		//获取Session
		Session s = this.getSessionFactory().openSession();
		//from后面是对象，不是表名
		String hql="from UserInfo as userInfo where userInfo.userCount=:count";//使用命名参数，推荐使用，易读。
		Query query=s.createQuery(hql);
		query.setString("count", userCount);
		
		@SuppressWarnings("unchecked")
		List<UserInfo> list=query.list();
		if(list != null && list.size() > 0){
			System.out.println("find!!");
			return true;
		}else{
			System.out.println("no find!!");
			return false;
		}	
	}
	
	public boolean addUser(UserInfo user){
		//获取Session
		Session s = this.getSessionFactory().openSession();
		s.beginTransaction();
		s.save(user);
		s.getTransaction().commit();
		return true;
	}
	
	public boolean addNoteBaseInfo(NoteBaseInfo noteBaseInfo){
		//获取Session
		Session s = this.getSessionFactory().openSession();
		s.beginTransaction();
		s.save(noteBaseInfo);
		s.getTransaction().commit();
		return true;
	}

	/**
	 * addDataDictionary
	 * @param DataDictionary dd
	 * @return void
	 */
	public void addDataDictionary(DataDictionary dd) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * loadUserInfo
	 * @param long id
	 * @return UserInfo
	 */
	public UserInfo loadUserInfo(long id) {
		//获取Session
		Session s = this.getSessionFactory().openSession();
		s.beginTransaction();
		UserInfo user = (UserInfo) s.load(UserInfo.class, id);
		s.getTransaction().commit();
		return user;
	}
	
	/**
	 * getUserInfo
	 * @param long id
	 * @return UserInfo
	 */
	public UserInfo getUserInfo(long id) {
		//获取Session
		Session s = this.getSessionFactory().openSession();
		s.beginTransaction();
		UserInfo user = (UserInfo) s.get(UserInfo.class, id);
		s.getTransaction().commit();
		return user;
	}
}
